//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System;
using System.ComponentModel;
using EntLibContrib.Query.Properties;

namespace EntLibContrib.Query.Configuration.Design
{
  /// <summary>
	/// Represents a <see cref="XmlParameterData"/> configuration element.
  /// </summary>
  public sealed class XmlParameterNode : ParameterNode
	{
		#region Fields
		private string namespaceName;
		#endregion

		#region Properties
		/// <summary>
		/// Gets or sets the Namespace for the current parameter.
		/// </summary>
		/// <value>
		/// The Namespace for the current parameter
		/// </value>
		[QueryCategory("CategoryGeneral")]
		[QueryDescription("XmlParameterNamespaceDescription")]
		public string Namespace
		{
			get { return namespaceName; }
			set { namespaceName = value; }
		}

		/// <summary>
		/// Gets the <see cref="ParameterData"/> this node represents.
		/// </summary>
		/// <value>
		/// The <see cref="ParameterData"/> this node represents.
		/// </value>
		[ReadOnly(true)]
		public override ParameterData ParameterData
		{
			get { return new XmlParameterData(Name, namespaceName); }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initialize a new instance of the <see cref="XmlParameterNode"/> class.
		/// </summary>
		public XmlParameterNode()
			: this(new XmlParameterData(InternalResources.DefaultXmlParameterNodeName, string.Empty))
    {
		}

		/// <summary>
		/// Initialize a new instance of the <see cref="XmlParameterNode"/> class with an <see cref="XmlParameterData"/> instance.
		/// </summary>
		/// <param name="xmlParameterData">The data parameter data.</param>
		public XmlParameterNode(XmlParameterData xmlParameterData)
    {
			if (xmlParameterData == null)
      {
				throw new ArgumentNullException("xmlParameterData");
      }

			Rename(xmlParameterData.Name);
			this.namespaceName = xmlParameterData.Namespace;
		}
		#endregion

		#region Public Methods
		/// <summary>
		/// Clones this instance.
		/// </summary>
		/// <returns></returns>
		public override ParameterNode Clone()
		{
			return new XmlParameterNode((XmlParameterData)this.ParameterData);
		}
		#endregion
	}
}